#include <string>
#include "SOR.h"
#include <chrono>

typedef std::chrono::high_resolution_clock myclock;
using namespace std;
int main(int argc, char ** argv)
{
  ifstream finA("A.m");
  if(!finA){
    cout << "Error input A" << endl;
  }
  ifstream finb("b.m");
  if(!finb){
    cout << "Error input b" << endl;
  }

  int nzn = 825737;
  int n = 119425;

  sparsematrix A(n,nzn);
  A.read(finA);
  vectorXd b(n);
  double a;
  for(int i = 0; i < n; i++){
    finb >> a;
    b[i] = a;
  }
  double w = 1.9;
  //for(w = 0.1; w < 2.0; w += 0.1){ //判断最佳松弛因子
    int IterativeTimes = 0;
    vectorXd x (n, 1);
    vectorXd y (n, 0);
    myclock::time_point begin = myclock::now();
    while(!convence(x,y,0.00005)){
      y = x;
      SorIterative(A, b, w, x);
      ++IterativeTimes;
    }
    myclock::duration d = myclock::now() - begin;
    cout << w << " " << IterativeTimes << ' ' << d.count() << endl;
    //}

  
  ofstream fout("solution.m");
  for(auto it = x.begin(); it != x.end(); ++it){
    fout << *it << "\n";
    }
  
  finA.close();
  finb.close();
  fout.close();
  return 0;
};
